package com.lgd.factoryattendance.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.graphics.Point;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lgd.factoryattendance.R;


public class ScreensaverActivity extends AppCompatActivity implements View.OnClickListener{
    TextView tv_screensaver,tv_clickText;
    LinearLayout layout_screensaver;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_screensaver);
        tv_screensaver = findViewById(R.id.tv_screensaver);
        SharedPreferences sharedPreferences = getSharedPreferences("device", MODE_PRIVATE);
        String projectName = sharedPreferences.getString("projectName","");
        tv_screensaver.setText(projectName);
        layout_screensaver = findViewById(R.id.layout_screensaver);
        layout_screensaver.setOnClickListener(this);
        SlideMonitor();
    }
    /** 获取屏幕坐标点 **/
    Point startPoint;// 起始点
    Point endPoint;// 终点
    /** 记录按下的坐标点（起始点）**/
    private float mPosX = 0;
    private float mPosY = 0;
    /** 记录移动后抬起坐标点（终点）**/
    private float mCurPosX = 0;
    private float mCurPosY = 0;

    //  监听 滑动监听
    public void SlideMonitor(){
        layout_screensaver.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        mPosX = event.getX();
                        mPosY = event.getY();
                        break;
                    case MotionEvent.ACTION_MOVE:
                        mCurPosX = event.getX();
                        mCurPosY = event.getY();
                        break;
                    case MotionEvent.ACTION_UP:
                         if (mCurPosY - mPosY < 0
                                && (Math.abs(mCurPosY - mPosY) > 50)) {
                            finish();    // 退出
                        }
                }
                return true;
            }
        });
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.layout_screensaver:
//                if (NoDoubleClickUtil.isFastDoubleClick()){return;}
//                finish();
                break;
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
    @Override
    public void finish() {
        super.finish();
        // 设置退出动画
        overridePendingTransition(0, R.anim.push_bottom_out);
    }
}